/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO;

//import java.beans.Statement;
import java.util.*;
import java.sql.*;

/**
 *
 * @author MinhHieu
 */
public class MySQLDataAccessHelper {

    private Connection connection;

    public void open() {
        try {
            DriverManager.registerDriver(new org.gjt.mm.mysql.Driver());
            String connectionString = "jdbc:mysql://localhost/quanlyhocsinh";
            Properties pros = new Properties();
            pros.setProperty("characterEncoding", "utf8");
            pros.setProperty("user", "root");
            this.connection = DriverManager.getConnection(connectionString, pros);
        } catch (Exception ex) {
            System.out.print(ex.getMessage());
        }
    }

    public void close() {
        try {
            this.connection.close();
        } catch (Exception ex) {
            System.out.print(ex.getMessage());
        }
    }
    //rut trich du lieu

    public ResultSet excecuteQuery(String sql) {
        ResultSet rs = null;
        try {
            Statement rm = this.connection.createStatement();
            rs = rm.executeQuery(sql);
        } catch (Exception ex) {
            System.out.print(ex.getMessage());
        }
        return rs;
    }
    // Them xoa update
    public int excecuteUpdate(String sql) {
        int num = -1;
        try {
            Statement rm = this.connection.createStatement();
            num = rm.executeUpdate(sql);
        } catch (Exception ex) {
            System.out.print(ex.getMessage());
        }
        return num;
    }
}
